package com.alien.admin.modules.deploy.domain;

import lombok.Data;

import java.util.ArrayList;
import java.util.List;

/**
 * Copyright (C), 2014-2021, 厦门神州鹰软件科技有限公司
 * FileName: ServiceDeployParam
 *
 * @author: zengzf
 * Date:     2021/9/29 16:48
 * Description:
 * History:
 */
@Data
public class ServiceDeployParam {

    private Resource resource;
    private Integer replicas;
    private HealthCheck healthcheck;
    private List<Port> ports;
    private List<Volume> volumes;
    private List<VolumeMount> volumeMounts;

    @Data
    public static class Res {
        private String cpu;
        private String memory;
    }

    @Data
    public static class Resource {
        private Res requests;
        private Res limits;
    }

    @Data
    public static class HealthCheck {
        private Integer livenessDelaySeconds;
        private Integer readinessDelaySeconds;
        private Integer periodSeconds;
        private String path;
    }

    @Data
    public static class Port {
        private String name;
        private Integer containerPort;
        private String protocol;

        public static Port valueOf(String name, Integer containerPort, String protocol) {
            Port p = new Port();
            p.setName(name);
            p.setContainerPort(containerPort);
            p.setProtocol(protocol);
            return p;
        }
    }

    @Data
    public static class Volume {
        private String name;
        private String claimName;
    }

    @Data
    public static class VolumeMount {
        private String name;
        private String mountPath;
        private String subPathExpr;
        private Boolean readOnly;
    }

    public static List<Port> getDefaultPortsConfig() {
        List<Port> ports = new ArrayList<>();
        ports.add(Port.valueOf("server", 38000, "TCP"));
        ports.add(Port.valueOf("dubbo", 38001, "TCP"));
        ports.add(Port.valueOf("jvmdebug", 38002, "TCP"));
        return ports;
    }

}

